package org.ribbon.consumer.service.impl;

import org.ribbon.consumer.service.ITestRibbonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Service
public class TestRibbonServiceImpl implements ITestRibbonService {

	@Autowired
    RestTemplate restTemplate;
	
	@Override
	@HystrixCommand(fallbackMethod = "errorBack")
	public String testRibbon(String name) {
		return restTemplate.getForObject("http://EUREKA-CLIENT/test?name=" + (name==null?"":name), String.class);
	}

	public String errorBack(String name) {
        return "hi, " + name + ", sorry error!";
    }
}
